package com.cqc.tablayoutdemo.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.cqc.tablayoutdemo.fragment.BaseFragment;
import com.cqc.tablayoutdemo.fragment.Frag1;
import com.cqc.tablayoutdemo.fragment.Frag2;
import com.cqc.tablayoutdemo.fragment.Frag3;

import java.util.List;

/**
 * Created by cui on 2016/10/30.
 */

public class MyAdapter extends FragmentPagerAdapter {
    private List<String> titleList ;
    public MyAdapter(FragmentManager fm,List<String> titleList) {
        super(fm);
        this.titleList = titleList;
    }

    @Override
    public Fragment getItem(int position) {
        BaseFragment fragment = null;
        switch (position) {
            case 0:
                fragment = new Frag1();
                break;
            case 1:
                fragment = new Frag2();
                break;
            case 2:
                fragment = new Frag3();
                break;
        }
        return fragment;
    }

    @Override
    public int getCount() {
        return titleList.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titleList.get(position);
    }
}
